<template>
	<view class="card-detail">
		<u-cell-group>
			<u-cell v-for="item in recordList" :key="item.id" :index="item.id">
				<view slot="title">
					<view class="name" style="color: #4f58ff">{{item.remark}}</view>
					<view class="date">{{ item.create_time }}</view>
				</view>
				<!-- 计次卡 -->
				<!-- <view slot="value" class="text-right" v-show="item.card_type == 1">
					<view class="number" v-if="item.op == 0" style="color: #4f58ff"><text>+</text> {{ item.times }}<text
							v-if="item.gift_times != ''" style="color: #ff0000;">赠{{ item.gift_times}}</text></view>
					<view class="rest" v-if="item.else_times">剩余:{{ item.else_times }}次</view>
				</view> -->
				<!-- 私教卡 -->
				<!-- <view slot="value" class="text-right" v-show="item.card_type == 4">
					<view class="number" v-if="item.op == 0" style="color: #4f58ff"><text>+</text> {{ item.times }}<text
							v-if="item.gift_times != ''" style="color: #ff0000;">赠{{ item.gift_times}}</text></view>
					<view class="rest" v-if="item.else_times">剩余:{{ item.else_times }}次</view>
				</view> -->
				<!-- 金额卡 -->
				<view slot="value" class="text-right" >
					<view class="number">
						<!-- <text>+</text> {{ item.money }} -->
						<text style="color: #ff0000;">{{ item.minus}}</text> </view>
					<view class="rest">基础值剩余:{{ item.recharge_old }}</text></view>
					<view class="rest">赠送值剩余:{{ item.gift_residue }}</view>
				</view>
				<!-- 时间卡 -->
				<!-- <view slot="value" class="text-right" v-show="item.card_type == 2">
					<view class="number" v-if="item.op == 0" style="color: #4f58ff"><text>+</text> {{ item.days }}<text
							v-if="item.gift_days != ''" style="color: #ff0000;">赠{{ item.gift_days}}</text></view>
					<view class="rest" v-if="item.else_days">剩余:{{ item.else_days }}天</view>
				</view> -->
			</u-cell>
		</u-cell-group>

		<!-- <u-cell-group >
			<u-cell v-for="item in recordList" :key="item.id">
				<view slot="title">
					<view class="name">{{ item.name }}</view>
					<view class="date">{{ item.date }}</view>
				</view>
				<view slot="value" class="text-right">
					<view class="number">{{ item.number }}</view>
					<view class="rest" v-if="item.rest">剩余:{{ item.rest }}次</view>
				</view>
			</u-cell>
		</u-cell-group> -->


	</view>
</template>

<script>
	const index = require('@/api/index/index.js')
	export default {
		data() {
			return {
				recordList: [],
				listQuery: { //分页
					pageNo: 1,
					pageSize: 6,
				},
				totalPage: '', //几页
				card_id:''
			}
		},
		onLoad(options) {
			this.card_id = options.card_id
			this.user_card_log()
		},
		methods: {
			// 金额计算保留两位小数
			amount(value) {
				return parseFloat(value).toFixed(2);
			},
			// 获取卡消费记录
			async user_card_log() {
				let that = this;
				if (this.listQuery.current === 1) that.recordList = [];
				let params = {
					'card_id-=': this.card_id,
					'page': this.listQuery.pageNo,
					'limit': this.listQuery.pageSize,
					'order': 'desc',
					'sort': 'id',
				}
				let res = await index.user_card_log(params)
				if (res && res.code == 1) {
					console.log(res.data.rows,'【【')
					that.recordList = that.recordList.concat(res.data.rows); //将数据拼接在一起
					that.totalPage = res.data.total
				}
			},
			// 下拉刷新
			onReachBottom() {
				if (this.totalPage <= this.listQuery.current) {
					uni.showToast({
						title: '没有更多了',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				this.listQuery.current += 1;
				this.user_card_log()
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import url("@/static/css/personal/index.css");

	.card-detail {
		padding-bottom: env(safe-area-inset-bottom);

		.top {
			padding: 30rpx;
		}


		/deep/.u-cell-group {
			.name {
				color: #333;
				font-weight: bold;
			}

			.number {
				color: #ff4105;
			}

			.date {
				color: #ccc;
			}

			.rest {
				color: #9c9c9c;
			}

			.rest,
			.date {
				margin-top: 14rpx;
				font-size: 26rpx;
			}
		}
	}
</style>
